package com.example.book.configuration;

import com.example.book.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    //自定义拦截对象
    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截对象
        registry.addInterceptor(loginInterceptor)
                //设置拦截器请求路径,代表url中的路径
                .addPathPatterns("/**")
                //排除路径
                .excludePathPatterns("/user/login")
//                .excludePathPatterns("/static/**"); //不能直接使用static/**
                //需要把静态文件排除
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/pic/**")
                .excludePathPatterns("/**/*.html");
    }
}
